﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Net;

using EHTWebsite.Code;
using EHTWebsiteProject.Code.BLL;
using System.Resources;
using System.Threading;
using System.Globalization;
using System.Text;
using EHTWebsiteProject.Code.Entity;

namespace EHTWebsiteProject.Administrator
{
    public partial class EHTChoiseLinkMenu : System.Web.UI.Page
    {
        public Boolean IsVN = true;                  
        private String languageCode = "vi-VN";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));
        private Int32 DMTypeMenu;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {                             

                try
                {
                    languageCode = Session[HangSo.LANGUAGE_CODE].ToString();
                    if (languageCode == "en-us")
                    {
                        IsVN = false;
                    }
                }
                catch (Exception ex) {
                }
                try
                {
                    DMTypeMenu = Int32.Parse(Request.QueryString["TypeMenu"].ToString());
                }
                catch
                {
                    DMTypeMenu = HangSo.Index;
                }
                Session["DMTypeMenu"] = DMTypeMenu.ToString();
                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                LoadLanguage(Thread.CurrentThread.CurrentCulture);
                if (IsVN == true)
                    lbAdd_Edit.Text = HangSo.Add_VN;
                else
                    lbAdd_Edit.Text = HangSo.App_Other;
                LoadTreeList();
            }
        }

        /// <summary>
        /// Ham load ngon ngu
        /// </summary>
        /// <param name="ci"></param>
        public void LoadLanguage(CultureInfo ci)
        {            
            lbHelp.Text = rm.GetString("lbHelp", ci);
            lbCancel.Text = rm.GetString("lbCancel", ci);
            plMenu.GroupingText = rm.GetString("plMenu",ci);
        }

        public void LoadTreeList()
        {
            if (IsVN == true)
            {
                TreeNode menu = new TreeNode(HangSo.DMMenu, "0");
                TreeNode dmsanpham = new TreeNode(HangSo.DMSanPham, "1");
                TreeNode sanpham = new TreeNode(HangSo.sanpham, "2");
                TreeNode dmTin = new TreeNode(HangSo.DMTin, "3");
                TreeNode tintuc = new TreeNode(HangSo.baiviet, "4");
                TreeNode dmkhac = new TreeNode(HangSo.dmKhac, "5");    
                menu.ChildNodes.Add(dmsanpham);
                menu.ChildNodes.Add(sanpham);
                menu.ChildNodes.Add(dmTin);
                menu.ChildNodes.Add(tintuc);
                menu.ChildNodes.Add(dmkhac);
                trvTypeMenu.Nodes.Add(menu);
            }
            else
            {
                TreeNode menuOther = new TreeNode(HangSo.DMMenuOther, "0");
                TreeNode dmsanphamOther = new TreeNode(HangSo.DMSanPhamOther, "1");
                TreeNode sanphamOther = new TreeNode(HangSo.sanphamOther, "2");
                TreeNode dmTinOther = new TreeNode(HangSo.DMTinOther, "3");
                TreeNode tintucOther = new TreeNode(HangSo.baivietOther, "4");
                TreeNode Other = new TreeNode(HangSo.dmOther, "5");
                menuOther.ChildNodes.Add(menuOther);
                menuOther.ChildNodes.Add(dmsanphamOther);
                menuOther.ChildNodes.Add(sanphamOther);
                menuOther.ChildNodes.Add(dmTinOther);
                menuOther.ChildNodes.Add(tintucOther);
                menuOther.ChildNodes.Add(Other);               
                trvTypeMenu.Nodes.Add(menuOther);
            }
            
        }

        protected void trvTypeMenu_SelectedNodeChanged(object sender, EventArgs e)
        {
            if (trvTypeMenu.SelectedNode.Value.ToString() == "0")
            {
                if (IsVN == true)
                    ltrErorr.Text = HangSo.meagessddl;
                else
                    ltrErorr.Text = HangSo.meagessddlOther;
                return;
            }
            else
                Response.Redirect("EHTCreateMenuIndex.aspx?ID=" + this.trvTypeMenu.SelectedNode.Value + "&&DM=" + Session["DMTypeMenu"].ToString());
        }
    }
}